package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.core.domain.JsonResponse;
import com.ruoyi.system.domain.dto.TTaskJobDto;
import com.ruoyi.system.domain.po.TTaskLog;
import com.ruoyi.system.domain.vo.TTaskJobVo;
import com.ruoyi.system.service.TTaskJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nanyang
 */
@RestController
@RequestMapping("/taskJob")
@Api(tags = "抓取、上报任务管理")
public class TTaskJobController {

    @Resource
    TTaskJobService taskJobService;


    @ApiOperation("新增任务")
    @PostMapping("/insertTaskJob")
    public JsonResponse insertTaskJob(@RequestBody @Validated TTaskJobDto.Insert taskJobInsert){
        return JsonResponse.ok(taskJobService.insertTaskJob(taskJobInsert));
    }

    @ApiOperation("修改任务")
    @PostMapping("/updateTaskJob")
    public JsonResponse updateTaskJob(@RequestBody @Validated TTaskJobDto.Update taskJobUpdate){
        return JsonResponse.ok(taskJobService.updateTaskJob(taskJobUpdate));
    }

    @ApiOperation("删除任务")
    @PostMapping("/deleteTaskJob")
    public JsonResponse deleteTaskJob(@RequestBody @Validated TTaskJobDto.Delete taskJobDelete){
        return JsonResponse.ok(taskJobService.deleteTaskJob(taskJobDelete));
    }

    @ApiOperation("查询任务列表")
    @PostMapping("/listTaskJob")
    public JsonResponse<PageInfo<TTaskJobVo>> listTaskJob(@RequestBody @Validated BaseDto<TTaskJobDto.Query> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(taskJobService.listTaskJob(list.getParam())));
    }

    @ApiOperation("新增任务子表")
    @PostMapping("/insertExtend")
    public JsonResponse insertExtend(@RequestBody @Validated TTaskJobDto.ExtendInsert extendInsertInsert){
        return JsonResponse.ok(taskJobService.insertExtend(extendInsertInsert));
    }

    @ApiOperation("修改任务子表")
    @PostMapping("/updateExtend")
    public JsonResponse updateExtend(@RequestBody @Validated TTaskJobDto.ExtendUpdate extendUpdate){
        return JsonResponse.ok(taskJobService.updateExtend(extendUpdate));
    }

    @ApiOperation("删除任务子表")
    @PostMapping("/deleteExtend")
    public JsonResponse deleteExtend(@RequestBody @Validated TTaskJobDto.ExtendDelete extendDelete){
        return JsonResponse.ok(taskJobService.deleteExtend(extendDelete));
    }

    @ApiOperation("查询接口日志")
    @PostMapping("/queryLog")
    public JsonResponse<PageInfo<TTaskLog>> queryLog(@RequestBody @Validated BaseDto<TTaskJobDto.LogQuery> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(taskJobService.queryLog(list.getParam())));
    }
}
